package com.cpr.ams.web.controller;

import com.cpr.ams.bean.Renting;
import com.cpr.ams.bean.extend.RentingExtend;
import com.cpr.ams.service.IRentingService;
import com.cpr.ams.util.Result;
import com.cpr.ams.util.StringAndDateUtil;
import com.jacky.base.utils.PageVM;
import com.sun.istack.internal.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description = "租房操作相关接口，暂时不用了")
@Validated
@RestController
@RequestMapping("/renting")
public class RentingController {
    @Autowired
    private IRentingService rentingService;
    @ApiOperation(value = "插入或更新租房")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键",dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "tenantId", value = "租户id",paramType = "query",required = true),
            @ApiImplicitParam(name = "roomId", value = "房间id",paramType = "query",required = true),
            @ApiImplicitParam(name = "startTime", value = "开始时间",paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间",paramType = "query"),
            @ApiImplicitParam(name = "amount", value = "支付金额",paramType = "query"),
            @ApiImplicitParam(name = "payStatus", value = "支付状态 目前只有一种状态，1.已支付 写数字代表",paramType = "query",dataType = "Integer"),

    })
    @PostMapping("/saveOrUpdateRenting")
    public Result saveOrUpdateRenting(Integer id,@NotNull Integer tenantId, @NotNull Integer roomId,String startTime,String endTime,Long amount, Integer payStatus){
        Renting renting=new Renting();
        renting.setId(id);
        renting.setTenantId(tenantId);
        renting.setRoomId(roomId);
        renting.setStartTime(StringAndDateUtil.stringToDate(startTime));
        renting.setEndTime(StringAndDateUtil.stringToDate(endTime));
        renting.setAmount(amount);
        renting.setPayStatus(payStatus);
        rentingService.saveOrUpdateRenting(renting);
        return Result.success("插入或更新成功");
    }
    @ApiOperation(value = "分页查询租房信息")
    @GetMapping("/pageQuery")
    @ApiImplicitParams({ @ApiImplicitParam(name = "page", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "tenantId", value = "用户id", paramType = "query"),
            @ApiImplicitParam(name = "roomId", value = "房间id", paramType = "query")
    })
    public Result pageQuery(@NotNull Integer page, @NotNull Integer pageSize, Integer tenantId,Integer roomId) {
        PageVM<RentingExtend> pageVM = rentingService.query(page,pageSize,tenantId,roomId);
        return Result.success(pageVM);
    }
}
